package com.java.business.jxc.web;

import java.util.List;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.alibaba.fastjson.JSON;
import com.java.business.jxc.bean.B_BUILDER;
import com.java.business.jxc.service.BuilderService;
import com.java.core.bean.ResultBean;
import com.java.core.utils.ResponseUtils;

@RequestMapping("/jxc/builder")
@Controller
public class BuilderController {

	@Autowired
	private BuilderService service;

	@RequestMapping("/add")
	public void add(HttpServletResponse response, B_BUILDER builder) {
		ResultBean rb = new ResultBean();
		try {
			service.add(builder);
		} catch (Exception e) {
			rb.setSuccess(false);
			rb.setMsg(e.getMessage());
		}
		ResponseUtils.renderJson(response, JSON.toJSONString(rb));
	}

	@RequestMapping("/update")
	public void update(HttpServletResponse response, B_BUILDER builder) {
		ResultBean rb = new ResultBean();
		try {
			service.update(builder);
		} catch (Exception e) {
			rb.setSuccess(false);
			rb.setMsg(e.getMessage());
		}
		ResponseUtils.renderJson(response, JSON.toJSONString(rb));
	}

	@RequestMapping("/setDisabled")
	public void setDisabled(HttpServletResponse response, B_BUILDER builder) {
		ResultBean rb = new ResultBean();
		try {
			service.setDisabled(builder);
		} catch (Exception e) {
			rb.setSuccess(false);
			rb.setMsg(e.getMessage());
		}
		ResponseUtils.renderJson(response, JSON.toJSONString(rb));
	}

	@RequestMapping("/delete")
	public void delete(HttpServletResponse response, String builder_id) {
		ResultBean rb = new ResultBean();
		try {
			service.delete(builder_id);
		} catch (Exception e) {
			rb.setSuccess(false);
			rb.setMsg(e.getMessage());
		}
		ResponseUtils.renderJson(response, JSON.toJSONString(rb));
	}

	@RequestMapping("/getBuilderList")
	public void getBuilderList(HttpServletResponse response, B_BUILDER builder) {
		ResultBean rb = new ResultBean();
		try {
			List<B_BUILDER> list = service.getBuilderList(builder);
			rb.setData(list);
		} catch (Exception e) {
			rb.setSuccess(false);
			rb.setMsg(e.getMessage());
		}
		ResponseUtils.renderJson(response, JSON.toJSONString(rb));
	}
}
